package com.itheima.controller;

import com.itheima.domain.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @Value("${gender}")
    private String gender;

    @Value("${person.name}")
    private String name;

    @Value("${person.age}")
    private int age;

    @Value("${person.gender}")
    private String gender2;

    @Value("${address[0]}")
    private String address;

    @Value("${msg1}")
    private String msg1;

    @Value("${msg2}")
    private String msg2;

    @Autowired
    private Environment env;

    @Autowired
    private Person person;

    @RequestMapping("/hello")
    public String demo() {
        return "Hello SpringBoot !!!";
    }

    @RequestMapping("/test")
    public void test(){
        System.out.println(gender);
        System.out.println(name);
        System.out.println(age);
        System.out.println(gender2);
        System.out.println(address);
        System.out.println(msg1);
        System.out.println(msg2);
    }

    @RequestMapping("/test2")
    public void test2(){
        System.out.println(env.getProperty("person.name"));
        System.out.println(env.getProperty("person.age"));
        System.out.println(env.getProperty("address[1]"));
        System.out.println(env.getProperty("msg2"));
    }

    @RequestMapping("/test3")
    public void test3(){
        System.out.println(person);
    }
}
